define(function(require) {

    var conflictValidator = {

        /**
         * 拖课课程后，以教学班的视角，检查是否有冲突
         * @param  {[type]} arranges    [description]
         * @param  {[type]} arrange    [description]
         * @param  {[type]} changedData [description]
         * @return {[type]}             [description]
         */
        validateByJxbView: function(arranges, arrange, changedData) {
            var _commonLib = require('./commonLib');

            for (var i = 0; i < arranges.length; i++) {
                var a = arranges[i];
                if (a.uuid === arrange.uuid) {
                    continue;
                }

                // [[验证时间是否冲突]]
                // 1. 检查周次是否有交集
                if (!_commonLib.hasIntersection(a.weekNum, arrange.weekNum)) {
                    continue;
                }
                // 2.检查星期是否一致
                if (a.week !== changedData.week) {
                    continue;
                }
                // 3.检查节次是否交叉
                // begin1 <= end2 && end1 >= begin1 表示有交叉
                if (parseInt(a.beginUnit) <= parseInt(changedData.endUnit) && parseInt(a.endUnit) >= parseInt(changedData.beginUnit)) {
                    return '课程时间存在冲突';
                }
            }
        },

        /**
         * 验证两个时间对象是否有交叉
         * @param  {[type]} timeObj1 [description]
         * @param  {[type]} timeObj2 [description]
         * @return {[type]}          [description]
         */
        validateTimeObj: function(timeObj1, timeObj2) {
            var _commonLib = require('./commonLib');

            if (_commonLib.hasIntersection(timeObj1.weekNum, timeObj2.weekNum)) {
                if (timeObj1.week === timeObj2.week) {
                    if (parseInt(timeObj1.beginUnit) <= parseInt(timeObj2.endUnit) && parseInt(timeObj1.endUnit) >= parseInt(timeObj2.beginUnit)) {
                        return true;
                    }
                }
            }
            return false;
        }
    };

    return conflictValidator;

});
